<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="/stylesheets/login.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
    </script>
</head>
<body>

<div class="contrainer">
    <div class="top">
        <p>登录</p>
    </div>
    <div class="middle">
        <input id="name" type="text" placeholder="用户名" name="username" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;" >
        <input id="pwd" type="password" placeholder="密码" name="password" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
    </div>
    <div class="bottom">
        <button id="reg" onclick="reClick()">注册</button>
        <button id="login" onclick="loginClick()">登录</button>
    </div>

    <script>
        function loginClick() {
            var name = document.getElementById("name").value;
            var pwd = document.getElementById("pwd").value;
            if(name==""){
                alert("用户名不能为空");
                return;
            }
            else if(pwd==""){
                alert("密码不能为空");
                return;
            }
            $.post("/login",{
                    username:name,
                    password:pwd
                },
                function(data,status){
                    var dataObj=eval("("+data+")");//转换为json对象
                    if(dataObj.status==200||dataObj.status==201){
                        window.location.href='home';
                    }
                    else {
                        alert("数据: \n" + dataObj.msg + "\n状态: " + dataObj.status);
                    }
                });


        }

        function reClick() {

            window.location.href='reg';
//
//
//            $.get("reg", function(result){
//
//            });
        }

    </script>

</div>

</body>
</html>